<?php

namespace App\Http\Controllers\Teacher;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\Users;
use App\Model\Roles;
use App\Model\Article;
use Auth;

class IndexController extends CommonController
{
    public function index(){
		$users = new Users;
        $article = new Article;
    	$user_info = Auth::user();
    	// 获取总人数
    	$data['nowAll'] = $users->count();
    	// 今天的时间段
    	$firstTime = strtotime(date('Y/m/d'));
    	$lastTime = $firstTime*86400;

    	// 今天增加会员
    	$data['dayAll'] = $users->where('reg_time','>',$firstTime)
    					->where('reg_time','<',$lastTime)->count();

        // 我的文章数
        $data['artAll'] = $article->where('uid',$user_info['id'])->count();

    	// 当前ip
    	$data['login_ip'] = long2ip($user_info->login_ip);

        // 当前身份
    	$data['role'] = $user_info['is_teacher']?'教师':'非法入侵者';

    	// 上一次登录时间
    	$data['last_login_time'] = date('Y-m-d H:i:s',$user_info->last_login_time);

    	// 服务器环境
    	$data['servers'] = $_SERVER ['SERVER_SOFTWARE'];

    	// 最大上传
    	$data['upload_max'] = ini_get('upload_max_filesize');
		return view('teacher.index',$data);
	}
}
